package cn.manyufun.myf.common.commonutils;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author Kevin Xiao
 * @date Create Date: 2018-03-02
 * @Description
 */
public class RequestBodyUtils {
    public static RequestBody getLikeRequestBody(int actionType, long referenceId) {
        return getLikeRequestBody(actionType, referenceId, 1);
    }

    /*:
    referenceTypeType
    1是指点赞短评，不区分漫评的短评还是漫画的短评

    2是指点赞别人写的漫评文章*/
    public static RequestBody getLikeRequestBody(int actionType, long referenceId, int referenceType) {
        JSONObject root = new JSONObject();
        JSONObject head = APIUtils.getHeadParamter();
        try {
            root.put("Head", head);
            root.put("ActionType", actionType);
            root.put("ReferenceId", referenceId);
            root.put("ReferenceType", referenceType);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return RequestBody.create(MediaType.parse("application/json"), root.toString());
    }

    public static RequestBody getArticleReplyRequestBody(long articleId, String content, long parentId) {
        JSONObject root = new JSONObject();
        JSONObject head = APIUtils.getHeadParamter();
        try {
            root.put("Head", head);
            root.put("ArticleId", articleId);
            root.put("Content", content);
            root.put("ParentId", parentId);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return RequestBody.create(MediaType.parse("application/json"), root.toString());
    }

    public static RequestBody getModifyUserBody() {
        JSONObject root = new JSONObject();
        JSONObject head = APIUtils.getHeadParamter();
        try {
            root.put("Head", head);
            root.put("HeadImgUrl", "imgurl");
            root.put("Email", "email");
            root.put("Slogan", "Solgan");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        LogUtils.logd("xwx:" + root.toString());

        return RequestBody.create(MediaType.parse("application/json"), root.toString());
    }

    public static RequestBody getUpdateUserBody(String UID, String nickName, int gender, String birthday, String region, String slogan) {
        JSONObject root = new JSONObject();
//        JSONObject head = APIUtils.getHeadParamter();
        try {
//            root.put("Head", head);
            root.put("UID", UID);
            root.put("NickName", nickName);
            root.put("Gender", gender);
            root.put("Birthday", birthday);
            root.put("Region", region);
            root.put("Slogan", slogan);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        LogUtils.logd("xwx:" + root.toString());

        return RequestBody.create(MediaType.parse("application/json"), root.toString());
    }


    public static RequestBody toRequestBody(String value) {
        return RequestBody.create(MediaType.parse("text/plain"), value);
    }
}
